#include <iostream>
using namespace std;
#define int long long

const int maxn = 1e5+5;
int P = 0; 

signed main()
{
	string s;
	cin>>s;
	for(int i=0;i<s.size();i++) if(s[i] == 'P')	P++;
	int A = 0,T = 0,ans = 0;
	for(int i=s.size()-1;i>=0;i--){
		if(s[i] == 'P')	P--;
		if(s[i] == 'T')	T++;
		if(s[i] == 'A')	if(T != 0)	ans = (ans + P*T)%1000000007;
	}
	cout<<ans%1000000007;
	return 0;
}
